package model

import (
	"gorm.io/gorm"
	"time"
)

type BaseHeaderModel struct {
	ID int64 `gorm:"primarykey;comment:主键ID"`
}
type BaseFooterModel struct {
	CreatedAt time.Time `gorm:"column:create_time;comment:创建时间"`
	UpdatedAt time.Time `gorm:"column:update_time;comment:更新时间"`
	//DeletedAt gorm.DeletedAt
	IsDeleted gorm.DeletedAt `gorm:"type:tinyint(4);default:0;comment:删除标识 '' 未删除 0 已删除 1"`
}

//分页封装
func Paginate(page int, pageSize int) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if page == 0 {
			page = 1
		}
		switch {
		case pageSize > 100:
			pageSize = 100
		case pageSize <= 0:
			pageSize = 10
		}
		offset := (page - 1) * pageSize
		return db.Offset(offset).Limit(pageSize)
	}
}
